package com.example.webserver.controller;


import com.example.webserver.entity.Result;
import com.example.webserver.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUpdateController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception{
        String orginalFileName= file.getOriginalFilename();
        String filename= UUID.randomUUID().toString()+orginalFileName.substring(orginalFileName.lastIndexOf("."));
        String url= AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
